package com.fys.order.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Description:MQ消息接收
 * @Date:   2020/8/4 11:43
 * @Author: fys
 */
@Slf4j
@Component
public class MQReceive {

    //1. 需手动在后台创建队列 @RabbitListener(queues = "myQueue")
    //2. 自动创建队列 @RabbitListener(queuesToDeclare = @Queue("myQueue"))
    //3. 自动创建 Exchange和Queue自动绑定
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("myQueue"),
            exchange = @Exchange("myExchange")
    ))
    public void process(String message){
        log.info("MqReceiver: {}", message);
    }


    /**
    * @Description: 电脑供应商的订单接收
    */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myExchange"),
            value = @Queue("myQueue"),
            key = "computer"
    ))
    public void processComputer(String message){
        log.info("processComputer: {}", message);
    }

    /**
     * @Description: 水果供应商的订单接收
     */
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange("myExchange"),
            value = @Queue("myQueue"),
            key = "fruit"
    ))
    public void processFruit(String message){
        log.info("processFruit: {}", message);
    }

}
